package be.vsko.zelfevaluatie.jackson.mapping;

import java.util.ArrayList;
import java.util.List;

import org.codehaus.jackson.map.annotate.JsonSerialize;

import be.vsko.zelfevaluatie.help.QueryParameters;
import be.vsko.zelfevaluatie.rest.RoaServlet;

public class Document {
	private Meta meta;
	private List<Resource> result = new ArrayList<Resource>();
	private String parent;
	
	public Document(RoaServlet servlet) {
		this.meta = new Meta();
		this.parent = servlet.getHref("/");
	}
	
	public Meta getMeta() {
		return meta;
	}
	
	public void setMeta(int count, QueryParameters query, RoaServlet servlet) {
		this.meta.setCount(count);
		if(query.getOffset() > 0)
			this.meta.setPrevious( servlet.getMetaHref(false, query) );
		if(query.getLimit()+query.getOffset() < count)
			this.meta.setNext( servlet.getMetaHref(true, query) );
	}
	
	public List<Resource> getResult() {
		return result;
	}

	public void setResult(List<Resource> result) {
		this.result = result;
	}

	public String getParent() {
		return parent;
	}

	@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
	public class Meta {
		private int count;
		private String previous;
		private String next;
		
		public Meta() {
			
		}

		public int getCount() {
			return count;
		}

		public void setCount(int count) {
			this.count = count;
		}

		public String getPrevious() {
			return previous;
		}

		public void setPrevious(String previous) {
			this.previous = previous;
		}

		public String getNext() {
			return next;
		}

		public void setNext(String next) {
			this.next = next;
		}
	}
}
